
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)





AI21[#](#ai21 "跳转到标题")
======================

[AI21 Studio](https://docs.ai21.com/) 提供 API 访问 `Jurassic-2` 大型语言模型。

本示例介绍如何使用 LangChain 与 [AI21 模型](https://docs.ai21.com/docs/jurassic-2-models) 进行交互。

```python
# install the package:
!pip install ai21

```

```python
# get AI21_API_KEY. Use https://studio.ai21.com/account/account

from getpass import getpass
AI21_API_KEY  = getpass()

```

```python
from langchain.llms import AI21
from langchain import PromptTemplate, LLMChain

```

```python
template = """Question: {question}

Answer: Let's think step by step."""

prompt = PromptTemplate(template=template, input_variables=["question"])

```

```python
llm = AI21(ai21_api_key=AI21_API_KEY)

```

```python
llm_chain = LLMChain(prompt=prompt, llm=llm)

```

```python
question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.run(question)

```

```python
'\n1. What year was Justin Bieber born?\nJustin Bieber was born in 1994.\n2. What team won the Super Bowl in 1994?\nThe Dallas Cowboys won the Super Bowl in 1994.'

```

